package java_thinking.unit_18_IO._18_13;

import java.util.prefs.BackingStoreException;
import java.util.prefs.Preferences;

/**
 * @Desc:   Preference ：是一个键值集合(类似映射)，存储在一个节点层次结构中
 *          userNodeForPackage : 偏向用于存储用户个人偏好
 *          systemNodeForPackage : 用于通用的安装配置
 * @author: cww
 * @DateTime: 2019-05-19 15:56
 */

public class PreferenceDemo {
    public static void main(String[] args) throws BackingStoreException {
        Preferences pre = Preferences.userNodeForPackage(PreferenceDemo.class);
        pre.put("Location", "Oz");
        pre.put("Footwear", "Ruby Slippers");
        pre.putInt("Companions", 4);
        pre.putBoolean("Are there witches?", true);
        int usageCount = pre.getInt("UsageCount", 0);
        usageCount++;
        pre.putInt("UsageCount:", usageCount);
        for (String key : pre.keys())
            //如果某个关键字下没有任何条目，那么这个参数就是所产生的默认值
            System.out.println(key + ": " + pre.get(key,null));
        System.out.println("How many companions does Dorothy have? " + pre.getInt("Companions", 0));
    }
}
